home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Libraries / GrafSys 2.0 / GrafSys 2.0 lib / GrafSys.Int < prev    next >
Encoding:
Text File  |  1993-08-18  |  22.0 KB  |  500 lines  |  [TEXT/PJMM]

  1. unit GrafSys;
  2.  
  3. {this is the interface file to the }
  4. {programmers hierachical 3D grafsys}
  5. { © 1993 by christian franz }
  6.  
  7. interface
  8.  
  9. {$IFC UNDEFINED UseFixedMath}
  10. {$SETC UseFixedMath := FALSE}
  11. {$ENDC}
  12.  
  13. {$PUSH}
  14. {$J+}
  15.  
  16. {Matrix/Vector/Surface manipulation }
  17.  
  18.  
  19. {$IFC UseFixedMath = TRUE }
  20. type
  21.     Matrix4 = record
  22.             M: array[1..4, 1..4] of fixed;
  23.             identity: boolean;
  24.         end;
  25.     Vector4 = array[1..4] of fixed;
  26.  
  27. var
  28.     one: fixed;
  29.  
  30. {$ELSEC}
  31.  
  32. type
  33.  
  34.     Matrix4 = record
  35.             M: array[1..4, 1..4] of real;
  36.             identityFlag: boolean;
  37.         end;
  38.     Vector4 = array[1..4] of real;
  39.  
  40. var
  41.     one: real;
  42.  
  43. {$ENDC}
  44. {returns the identity matrix}
  45. function Identity: Matrix4;
  46.  
  47. (* VSub : Subtract two vectors: result := x - y *)
  48. function VSub (x, y: Vector4): Vector4;
  49.  
  50. (* VAdd : Add two vectors *)
  51. function VAdd (x, y: Vector4): Vector4;
  52.  
  53. (* Set Vector to coordinates *)
  54. procedure SetVector4 (var theVector: Vector4; x, y, z: real);
  55.  
  56. (* get vector coordinates *)
  57. procedure GetVector4 (theVector: Vector4; var x, y, z: real);
  58.  
  59. (* IsVisible determines if the plane defined through the three points KLM (as vector 4)     *)
  60. (* is visible form the eye. Visibility is determined as the value of the normal vector of     *)
  61. (* the plane defined by abc. it is visible if the z component of n is greater than zero         *)
  62. (* note that for this test you must label k,l,m clockwise !!!                                     *)
  63.  
  64. function IsVisible (k, l, m: Vector4): Boolean;
  65.  
  66. {offscreen core data definitions }
  67.  
  68. type
  69.  
  70. TOffscreenRec = record (* offscreen data management *)
  71.         thePort: CGrafPtr;
  72.         theDevice: GDHandle;
  73.         theColors: CTabHandle;
  74.         mainDevice: GDHandle;
  75.     end;
  76.  
  77. {GrafSys core definitions }
  78.  
  79. const
  80.     {Misc Constants }
  81. Res3D = '3Dob'; (* This is the 3D object data resource name *)
  82. Res3DColor = 'lClr'; (* line color resource for 3Dob *)
  83.  
  84.     {Error Codes defined by the GrafSys }
  85. cNoFFallocated = -1;
  86. cOutOfMem = -2;
  87. cBadMethodCall = -3; {this method should not be called. Instance it yourself!}
  88. cNothingToInherit = -4; {this error occures when you try to pass on as first thing in the FF chain }
  89. cTooManyPoints = -5; {model database is full. Maximum # of points exceeded }
  90. cIllegalPointIndex = -6; {point index specified has no corresponding point in model }
  91. cTooManyLines = -7; {trying to add a line to a model that is full }
  92. cIllegalLineIndex = -8; {trying to access a line that does not exist }
  93. cCantDeletePoint = -9; {the point is still referenced by at least one line}
  94. cNotOwner = -10; {FF matrix doesn't belong to this object}
  95. cBadFF = -11;    {FF matrix was NIL}
  96. cBadFFType = -12; {FF matrix type cant be made current }
  97. cCantLoadRes = -13; {error loading resource }
  98. cNo3DWindow = -14; {Window passed is no 3D window }
  99. cCantCreateOffscreen = -15; {Error occured while trying to allocate Off-Screen PixMap}
  100. cCantChangeOffscreen = -16; {Error occured while trying to resize or recolor Off-Screen PixMap}
  101. cNoOSAttached = -17; {the 3D Window passed has no Off-Screen PixMap attached}
  102. cCantUseWindowCLUT = -18; {Current active window does not use indexed (1-8 bit/pixel) colors}
  103. cNoActiveOSPixMap = -19; {User did not call BeginOSDraw. no active pix map}
  104.     {other constants}
  105. cErrorAlertID = 32700; {standard error-handler alert }
  106.  
  107. type
  108. TGenericObject = object
  109.         ErrorCode: integer;
  110.         function Clone: TGenericObject;
  111.         procedure Kill; (* deallocate myself *)
  112.         procedure HandleError;
  113.         procedure ResetError;
  114.         function Test (opcode: integer): integer; (* does anything to check integrity of object         *)
  115.                                                         (* This incarnation just pops up the Error Dialog    *)
  116.                                                         (* and returns Error Code. Opcode is ignored         *)
  117.         procedure Init;                                (* just so it is defined for every object. Does nothing     *)
  118.                                                         (* but initialization of ErrorCode. Make sure you do this *)
  119.                                                         (* first, then do your own init if no error reported        *)
  120.         procedure Reset;                            (* reset this object. doesn't really do anything but provided *)
  121.                                                         (* so all objects support this method *)
  122.     end;
  123.  
  124.  
  125. TMatrixList = object(TGenericObject)
  126.         M: Matrix4;
  127.         next: TMatrixList;
  128.         owner: TGenericObject;                            {who owns this matrix? }
  129.         procedure Init; (* set matrix to identity *)
  130.         override;
  131.         procedure Reset;
  132.         override;
  133.         procedure TMRotate (dx, dy, dz: real);        {rotate this matrix further}
  134.         procedure TMScale (dx, dy, dz: real);        {scale this matrix further }
  135.         procedure TMTranslate (dx, dy, dz: real);    {Translate this matrix further }
  136.         procedure TMRotArbAchsis (p, x: Vector4; phi: real); {rotate around achsis defined by p and x}
  137.     end;
  138.  
  139. TMatrixInherit = object(TMatrixList)     {This links a string of inherited matrixes to a 'father' }
  140.         upLink: TMatrixList;                        {M contains the result of all MxM multiplie of prior }
  141.                                                     {Matrices. M is updated via the downlink whenever  }
  142.                                                     {father object gets updated. Update from father}
  143.         meTheSon: Tabstract3DObject;            {link to myself. Used for killing son when father gets}
  144.                                                     {kill message, father accesses this field via downlink}
  145.         procedure Init;
  146.         override;
  147.     end;
  148.  
  149. TMatrixPass = object(TMatrixList)        {this links a FFmatrix-string (up to here) to a son}
  150.         downLink: TMatrixInherit;                {whenever Transform is called, it will place the current }
  151.                                                     {result of the FF transformations in the downlinks M field }
  152.         meTheFather: Tabstract3DObject;        {link to myself}
  153.         procedure Init;
  154.         override;
  155.     end;
  156.  
  157.  
  158. Tabstract3DObject = object(TGenericObject)
  159.         xTrans, yTrans, zTrans: real;    {translation for origin}
  160.         xScale, yScale, zScale: Real;    {scale factors for object}
  161.         xrot, yrot, zrot: real;             { rotation in radiants }
  162.         xForm: Matrix4;                    { result of all xforms including freeform }
  163.         arbRot: Matrix4;                    { arbitrary rotation is stored here }
  164.         currentFF: TMatrixList;            {current FF matrix}
  165.         FFMatrix: TMatrixList;            { listhead of freeform xform matrices }
  166.         objChanged: Boolean;             {true if object description changed. A call to calcTransform will reset it}
  167.         versionsID: longint;                {used for sync with eye. If ID <> eyes ID a recalc is required }
  168.         hasChanged: boolean;                {true after calctransform call that changed data. Should be reset by Draw etc. }
  169.         procedure Init;                                        {initialize object}
  170.         override;
  171.         procedure Reset;                                    {reset all rot, trans, scale to default }
  172.         override;
  173.         function Clone: TGenericObject;                    {must also clone all TMatrix }
  174.         override;                                                {ATTN: what about inheritances??}
  175.         procedure Translate (dx, dy, dz: real);             { xlate object }
  176.         procedure SetTranslation (x, y, z: real);         { set xlation to fixed amount }
  177.         procedure Rotate (dx, dy, dz: real);                  { rotate further (just changes x-,y- and zrot) }
  178.         procedure SetRotation (x, y, z: real);              { set rot to x,y and z }
  179.         procedure Scale (dx, dy, dz: real);                  {scale factor for x, y and z }
  180.         procedure SetScale (x, y, z: real);                  {set absolute scale factor }
  181.         procedure RotArb (p, x: Vector4; phi: real);    {rotate around arbitrary axis}
  182.         procedure ResetArb;                                {reset arb operator to identity}
  183.         procedure FFTranslate (dx, dy, dz: real);          {xlate current FFMatrix further}
  184.         procedure FFRotate (dx, dy, dz: real);              {rotate current FFMatrix further }
  185.         procedure FFScale (dx, dy, dz: real);              {scale current FFMatrix further }
  186.         procedure FFRotArbAchsis (p, x: Vector4; phi: real); {rotate around achsis defined by p and x}
  187.         procedure FFReset;                                {resets *current* FFMatrix to Identity (i.e. not all) }
  188.         function FFNewPostConcat: TMatrixList;             {allocate new FF matrix and postconcat it, put it into currentFF}
  189.         function FFNewPreConcat: TMatrixList;            {allocate new FF matrix and preconcat it, put it into currentFF }
  190.         function FFActivate (theFF: TMatrixList): boolean;
  191.                                                                 {puts theFF into currentFF. Returns true if successful}
  192.         function FFPassOn: TMatrixPass;                    {generates a link for inheritance to 'son' object. I'm Father}
  193.                                                                 {it appends a link field to the FFMatrix list}
  194.                                                                 {does not update currentFF field}
  195.         procedure FFInherit (var FatherList: TMatrixPass);    {Preconcatenate Fathers list to current FF List }
  196.         procedure CalcTransform;                        {calculate xForm from rot,koord,scale and FF }
  197.         function ForeignPoint (p: Vector4): Vector4;    {convert p using current object's xForm. Call Transform first!}
  198.         function WorldToModel (wc: Vector4): Vector4; {xform world coordinates to model coordinates}
  199.         procedure Draw;                                    {not supported at this level }
  200.         procedure Kill;                                        {deallocate memory for this object. it will call kill for }
  201.         override;                                                {all associated FF matrices. If it passes on, it will deallocate }
  202.                                                                 {all sons and their FF matrices as well}
  203.     end;
  204.  
  205. TPoint3D = object(Tabstract3DObject)
  206.         Koord: Vector4;
  207.         procedure Init;
  208.         override;
  209.         procedure Reset;
  210.         override;
  211.         procedure SetKoords (Koordinates: Vector4);
  212.         function GetKoords: Vector4;
  213.     end;
  214.  
  215. TLine3D = object(Tabstract3DObject)
  216.         FromLoc: Vector4;
  217.         ToLoc: Vector4;
  218.         procedure Init;
  219.         override;
  220.         procedure Reset;
  221.         override;
  222.         procedure SetKoords (K1, K2: Vector4);
  223.         procedure GetKoords (var K1, K2: Vector4);
  224.     end;
  225.  
  226. (* return the error string that belongs to an error code *)
  227.  
  228. function InterpretError (theErr: integer): Str255;
  229.  
  230. {GrafSys Screen definitions}
  231. const
  232. {$IFC UseFixedMath = FALSE}
  233. MaxPointPerBuf = 1024 - 1; (* Maximum Points per Object : 256K *)
  234. {$ELSEC}
  235. { code for fixed math routines }
  236. MaxPointPerBuf = 1024 - 1;
  237. {$ENDC}
  238. MaxBuffers = 256 - 1;
  239. (* GrafSys constants *)
  240. cPort3DType = '3Prt';
  241. cGrafSysVersion = $00000001; (* = Version 0.01 *)
  242.  
  243. type
  244. ProjectionTypes = (parallel, perspective);
  245. clippingType = (none, arithmetic, fast);
  246.  
  247. TPort3DPtr = ^TPort3D;
  248. TPort3D = record
  249.         theWindow: CWindowRecord; (* piggy-back riding on the window's data we'll put everything else *)
  250.         versionType: OSType; (* used to veryfy that this record is really a 3dPort *)
  251.         theOffscreen: TOffscreenRec; (* for later use in off-screen drawing *)
  252.         ProjectionPlane: rect;
  253.         ViewPlane: rect;
  254.         left, right, top, bottom: integer;
  255.         center: point;
  256.         useEye: Boolean;    {if false, no eye transform necessary }
  257.         EyeKoord: Vector4;
  258.         ViewPoint: Vector4;
  259.         phi, theta, pitch: real;
  260.         ViewAngle: real;
  261.         d: real; {Perspective param set by viewangle }
  262.         MasterTransform: Matrix4; {matrix to transform all objects according to eye settings }
  263.         projection: ProjectionTypes;
  264.         clipping: ClippingType;
  265.         versionsID: longint; (* ID so objects can detect if the eye changed its specifications *)
  266.     end;
  267.  
  268. TSPoint3D = object(TPoint3D)
  269.         size: integer; (* size of point *)
  270.         procedure Init;
  271.         override;
  272.         procedure Reset;
  273.         override;
  274.         procedure Draw;    {draw point as seen from the eye. xForm (and Eye) are  applied. No Transform call required }
  275.         override;                {xForm is automatically calculated if neccessary. A Graf3DPort must be active! }
  276.     end;
  277.  
  278. TSLine3D = object(TLine3D)
  279.         procedure Draw;     {draw line as seen from the eye. xForm (and Eye) are  applied. No Transform call required }
  280.         override;                {xForm is automatically calculated if neccessary. A Graf3DPort must be active! }
  281.     end;
  282.  
  283. Point3DEntry = record
  284.         koords: Vector4;
  285.         transformed: vector4; (* transformed point, used with clipping *)
  286.         Screenx: integer;
  287.         Screeny: integer;
  288. {transformedZ: real;}
  289.     end;
  290.  
  291. Point3DBufPtr = ^Point3DBufRec;
  292. Point3DBufRec = array[0..MaxPointperBuf] of Point3DEntry;
  293.  
  294. TSGenericObject3D = object(Tabstract3DObject)     { this is the real 3D object that will be extended }
  295.         theBufs: array[0..MaxBuffers] of Point3DBufPtr;        { it contains only the points, nothing else }
  296.         currentBuf: Point3DBufPtr;
  297.         currentIndex: integer; (* index of current buffer *)
  298.         numPoints: longint; (* number of points in object *)
  299.         Bounds: rect; (* for auto-erase data gathering *)
  300.         oldBounds: Rect;
  301.         screenXform: Matrix4;                                {final xformation matrix including eye if useseye else}
  302.                                                                 {equal to xForm                                                         }
  303.         procedure Init;
  304.         override;
  305.         function Clone: TGenericObject;                    {duplicate point buffers as well }
  306.         override;
  307.         procedure Reset;                                    {reset all rots and attributes to default }
  308.         override;
  309.         procedure Kill;                                         {deallocate mem. Will kill all sons that inherit}
  310.         override;
  311.         procedure GenIndex (pointIndex: longint; var BufIndex, bufOffset: integer); {pointindex -> (buffer, offset) conversion }
  312.         function AddPoint (x, y, z: real): longint;        {add a point to the object's database. It returns the }
  313.                                                                 {points reference number if successful or -1 otherwise}
  314.                                                                 {point count is one-based, i.e. fist point is index 1. Note     }
  315.                                                                 {that this differs from the internal representation where }
  316.                                                                 {point count is zero-based. COMMON ERROR SOURCE!         }
  317.         function DeletePoint (index: longint): boolean;    {delete point with passed index from database. returns }
  318.                                                                 {false if operation could not be completed }
  319.                                                                 {delete does not deallocate mem if buffer is freed }
  320.                                                                 {all points beyond the one deleted will be moved to }
  321.                                                                 {compact mem}
  322.                                                                 {passing index <1 as index means delete all points}
  323.         procedure GetPoint (index: longint; var x, y, z: real);         {get points coordinate in model coords }
  324.                                                                                 {if point illegal, it returns 0,0,0}
  325.         function ChangePoint (index: longint; x, y, z: real): boolean;     {change points coords. true on success }
  326.         procedure Transform (forceCalc: boolean);        {calc trafo-matrix (if necessary) and convert   }
  327.                                                                 {all points to their screen representation           }
  328.                                                                             {WARNING: A 3D GrafPort must be open. The     }
  329.                                                                 {transformations are done for the currently ac-}
  330.                                                                 {tive 3D grafport's eye settings.}
  331.         procedure Transform2 (forceCalc: boolean);    (* calc trafo-matrix (if necessary) and convert    *)
  332.                                                                 (*all points to their screen representation. gather *)
  333.                                                                 (* information for auto-erasure                            *)
  334.  
  335.         function TransformedPoint (index: longint): Vector4;     {get transformed coordinates of point     }
  336.                                                                         {with index. if illegal proc will return     }
  337.                                                                         {0,0,0. Note that eye is not considered    }
  338.                                                                         {you have to use ToScreen for that        }
  339.         function ForeignPoint (p: Vector4): Vector4;    {as inherited except that eye trafo is included if}
  340.         override;                                                {useEye is set                                          }
  341.         function WorldToModel (wc: Vector4): Vector4;    {as inherited except that eye trafo is included}
  342.         override;                                                    {if useEye is set.                                    }
  343.         procedure CalcBounds;                                {calc bounds of object on screen and place it in    }
  344.                                                                 {the oldBounds variable.                                }
  345.     end;
  346.  
  347.  
  348. var
  349. current3Dport: TPort3Dptr; (* currently active 3D port *)
  350.  
  351.  
  352. (* procedures to intialize GrafSys and return version numbers *)
  353. procedure InitGrafSysScreen; (* initialize the GrafSys and local variables such as current graf 3D port *)
  354. function GrafSysVersion: longint; (* higword: major release, lower word : minor release. Hex 00010001 means version 1.01 *)
  355. (* procedure to create new 3D windows and grafports *)
  356.  
  357. function GetNew3DWindow (ID: integer; behind: ptr): WindowPtr; (* allocate a new window from resource *)
  358. function New3DWindow (boundsRect: Rect; title: Str255; visible: BOOLEAN; procID: Integer; behind: WindowPtr; goAwayFlag: BOOLEAN; refCon: LongInt): WindowPtr;
  359. procedure Dispos3DWindow (theWindow: WindowPtr); (* close and release mem occupied by the window *)
  360.  
  361. (* procedures affecting CURRENT  3D GrafPort *)
  362. procedure Set3DPort (the3DPort: WindowPtr);     (* tells grafsys in which port to draw. This port MUST have been *)
  363.                                                             (* previously allocated with New3DWindow or GetNew3DWindow  *)
  364. procedure Get3DPort (var the3DPort: WindowPtr);     (* returns current 3D GrafPort *)
  365. function Is3DPort (thePort: WindowPtr): Boolean;    (* returns TRUE if thePort is a 3D Port *)
  366. procedure SetView (ProjectPlaneSize, ViewPlaneSize: Rect);     (* sets the viewing and projection plane parameters *)
  367.                                                                             (* of the currently active 3D GrafPort                     *)
  368.                                                                             (* this of course affects the center location             *)
  369. procedure SetCenter (x, y: Integer);                (* Sets center of current 3D grafport to given params  *)
  370. procedure SetEyeChar (UsesEye: Boolean; location: Vector4; thePhi, theTheta, thePitch, theViewangle: real; clipType: clippingType);
  371.                                                             (* Sets eye characteristics and calculates window's master trans- *)
  372.                                                             (* form                                                                              *)
  373. procedure GetEye (var UsesEye: Boolean; var location: Vector4; thePhi, theTheta, thePitch, theViewangle: real; var clipType: clippingType);
  374.                                                             (* returns eye characteristic of current active 3d grafport *)
  375.  
  376. procedure ToScreen (thePoint: Vector4; var h, v: INTEGER); { transforms a point with x,y,z to screen as seen under    }
  377.                                                                     {current eye settings                                        }
  378. procedure ProjectPoint (thePoint: Vector4; var h, v: integer);
  379.         {project 3D pointz to screen using projection type}
  380.  
  381.  
  382. {GrafSys Object definitions }
  383. const
  384. MaxLine = 8000;
  385.  
  386. type
  387.  
  388. LineEntry = record
  389.         fromP, toP: longint; (* max 8000 lines per model supported in this incarnation.  *)
  390.         hs, vs, he, ve: integer; (* for fast drawing. buffers transformed locations *)
  391.         newline: boolean; (* for optimization. if true, no MoveTo required *)
  392.         newLineColor: boolean;
  393.         LineColor: RGBColor;
  394.     end;
  395.  
  396. LineBufPtr = ^LineBufRec;
  397. LineBufRec = array[1..MaxLine] of LineEntry;
  398.  
  399. TSObject3D = object(TSGenericObject3D)
  400.         Lines: LineBufPtr;
  401.         numLines: integer;
  402.         AutoErase: Boolean;
  403.         UseBounds: Boolean;
  404.         procedure Init;
  405.         override;
  406.         function Clone: TGenericObject;    {also clone line description buffer}
  407.         override;
  408.         procedure Reset;
  409.         override;
  410.         procedure Kill;
  411.         override;
  412.         function AddLine (fIndex, tIndex: longint): integer;        {add line to objects database. returns line index or -1}
  413.         function ChangeLine (LineIndex, fIndex, tIndex: longint): boolean;    {change line description of line with index }
  414.                                                                                     {lineIndex. True if successful                }
  415.         function ChangeLineColor (LineIndex: longint; theColor: RGBColor): boolean;
  416.                                                                         {change the color from this line on for all following }
  417.                                                                         {until the next ChangeColor command                      }
  418.         function GetLineColor (LineIndex: longint; var theColor: RGBColor; var ChangeHere: boolean): Boolean;
  419.                                                                         {returns the currently active color of specified line}
  420.         function KeepLineColor (LineIndex: longint): boolean;    {deletes change linecolor information. This line and }
  421.                                                                         {all following will have the same color as the pre-  }
  422.                                                                         {vious                                                      }
  423.         function DeleteLine (LineIndex: integer): Boolean;        {delete whole line from model. True on success}
  424.         function DeletePoint (index: longint): boolean;            {override inherited proc of this kind. This one checks}
  425.         override;                                                        {first if point is referenced to by a point. If so, it }
  426.                                                                         {returns false and doesn't delete the point            }
  427.         procedure GetLine (lineIndex: integer; var src, tgt: LongInt); {returns start and endpoint of line}
  428.         procedure BuildNewLines;    {should not be called from the outside}
  429.         procedure CollectLineData; {internal use only. fill the screen vals from point definition into line array}
  430.         procedure SetAutoerase (TurnOn: Boolean);                {controls setting of autoerase flag if switched on, }
  431.                                                                         {this procedure will initialize the oldBounds var    }
  432.         procedure SetUseBounds (TurnOn: Boolean);                {tells Draw and fDraw to collect bouding box data}
  433.         procedure Draw;                                            {recalcs if neccessary, erases old image if auto- }
  434.         override;                                                        {erase on, redraws all objects lines                     }
  435.         procedure fDraw;                                            {like Draw but it collects data prior to drawing }
  436.                                                                         {thus making the actual drawing process a bit  }
  437.                                                                         {faster but the whole call is slower than Draw }
  438.         procedure Erase;                                            {erase image of myself. this calcs and uses bounds}
  439.     end;
  440.  
  441. {Global Procedures for GrafSys}
  442. procedure InitGrafSys;
  443. procedure ArithmeticClip (var startV, endV: Point3DEntry; var skipThis, clippedThis: boolean; var sx, sy, ex, ey: integer);                                                                        {arithmetically clips a line that connects startV,endV }
  444.                                                                         {if it intersects the Z=0 plane. If it is completely behind }
  445.                                                                         {the Z=0 plane, skipThis is TRUE, if it intersects with }
  446.                                                                         {the plane, clippedThis becomes true and sx..ey contain}
  447.                                                                         {the new screen coordinates                                        }
  448.  
  449. {resource access }
  450. function GetNewObject (theObjectID: INTEGER): TSObject3D;        {Create new 3D object and fill with data from res}
  451. function GetNewNamedObject (theName: Str255): TSObject3D;
  452. procedure SaveObject (Obj: TSObject3D; theName: Str255; ID: integer);    {save data to resource with number = ID }
  453. procedure SaveNamedObject (Obj: TSObject3D; theName: Str255; var ID: integer);
  454.  
  455. {Off-screen Graphics }
  456. const
  457. cBitDepth = 8; (* Standard bit-depth for all offscreen devices GrafSys uses *)
  458. cMaxBitDepth = 8;
  459. cStdColorCLUT = 72;
  460.  
  461. var
  462. currOSPixMap: PixMapHandle;
  463.  
  464. function AttachOffScreen (theWindow: WindowPtr; theColors: CTabHandle): integer; (* attach OS port to window *)
  465. (* pass CTabHandle(-1) to use window's CLUT or CTabHandle(-2) as parameter if you want standard color CLUT *)
  466.  
  467. function ChangeOffscreen (theWindow: WindowPtr; theColors: CTabHandle): integer; (* make OS port the same as the window *)
  468. (* pass CTabHandle(-1) as parameter if no change to CLUT *)
  469.  
  470. function CloseOffscreen (theWindow: WindowPtr): integer; (* dispose OS port *)
  471.  
  472. function BeginOSDraw (theWindow: WindowPtr): integer; (* begin drawing to Off-Screen *)
  473. function EndOSDraw (theWindow: WindowPtr): integer; (* end drawing to Off-Screen *)
  474. function CopyOS2Screen (theWindow: WindowPtr; theRect: Rect; copyMode: Integer): integer; (* copy offscreen to screen *)
  475.  
  476.  
  477. { pascal long FastPixErase ( PixMapHandle pixH, short color) }
  478. procedure FastPixErase (pixH: PixMapHandle; color: integer);
  479.  
  480. { pascal void FillTriangle (Point p1, Point p2, Point p3, int theColor, Boolean forceQD); }
  481. procedure FillTriangle (p1: Point; p2: point; p3: Point; theColor: Integer; useQD: Boolean);
  482.  
  483. {$J-}
  484. {POP}
  485.  
  486. procedure SetPortX (w: GrafPtr);
  487. {Automatically switches 3D port as well if the window indicated is a}
  488. {3D window }
  489.  
  490.  
  491. implementation
  492.  
  493. procedure SetPortX (w: GrafPtr);
  494.     begin
  495.         if Is3DPort(w) then
  496.             Set3DPort(w);
  497.         SetPort(w);
  498.     end;
  499.  
  500. end.